package saxion.speelveld.spaceengineer.model;

import java.io.Serializable;
import java.util.ArrayList;

public abstract class ProducingBuilding extends Building implements Serializable
{
	public ProducingBuilding(int Width, int Height)
	{
		super(Width, Height);
		this.resourceProducedCosts = new ArrayList<Resource>();
		this.resourcesProducedGains = new ArrayList<Resource>();
		this.possibleResourceProducements = new ArrayList<Resource[]>();

	}

	private ArrayList<Resource> resourcesProducedGains;

	private ArrayList<Resource> resourceProducedCosts;

	private ArrayList<Resource[]> possibleResourceProducements;

	private Resource[] secondaryProducingChoice = null;

	public void addResourceProduceGain(Resource resource)
	{
		resourcesProducedGains.add(resource);
	}

	public void addPossibleResourceProducement(Resource gain, Resource cost)
	{
		Resource[] resourceArray = new Resource[] { gain, cost };
		possibleResourceProducements.add(resourceArray);
	}

	public ArrayList<Resource[]> getPossibleResourceProducements()
	{
		return this.possibleResourceProducements;
	}

	/***
	 * removes all resources from the list and sets it to the given one.
	 * 
	 * @param resource
	 */
	public void setResourceProduceGain(Resource resource)
	{
		resourcesProducedGains.clear();
		resourcesProducedGains.add(resource);
	}

	public ArrayList<Resource> getResourceProducedGainsOverTime()
	{
		ArrayList<Resource> ResourceGainsOverTime = new ArrayList<Resource>();
		for (Resource resource : resourcesProducedGains)
		{
			if (resource.isReOccuring() == true)
			{
				ResourceGainsOverTime.add(resource);
			}
		}
		return ResourceGainsOverTime;
	}

	public ArrayList<Resource> getResourceProducedGainsOnce()
	{
		ArrayList<Resource> ResourceGainsOverTime = new ArrayList<Resource>();
		for (Resource resource : resourcesProducedGains)
		{
			if (resource.isReOccuring() == false)
			{
				ResourceGainsOverTime.add(resource);
			}
		}
		return ResourceGainsOverTime;
	}

	public ArrayList<Resource> getResourcesProducedGains()
	{
		return resourcesProducedGains;
	}

	// public void setResourcesProducedGains(ArrayList<Resource> resourcesProducedGains)
	// {
	// this.resourcesProducedGains = resourcesProducedGains;
	// }

	// public boolean isReOccuringResourceCosts()
	// {
	// return reOccuringResourceCosts;
	// }
	//
	// public void setReOccuringResourceCosts(boolean reOccuringResourceCosts)
	// {
	// this.reOccuringResourceCosts = reOccuringResourceCosts;
	// }

	public ArrayList<Resource> getResourceProducedCosts()
	{
		return resourceProducedCosts;
	}

	public ArrayList<Resource> getResourceProducedCostsOverTime()
	{
		ArrayList<Resource> ResourceCostsOverTime = new ArrayList<Resource>();
		for (Resource resource : resourceProducedCosts)
		{
			if (resource.isReOccuring() == true)
			{
				ResourceCostsOverTime.add(resource);
			}
		}
		return ResourceCostsOverTime;
	}

	public void addResourceProduceCost(Resource resource)
	{
		resourceProducedCosts.add(resource);
	}

	public Resource[] getSecondaryProducingChoice()
	{
		return secondaryProducingChoice;
	}

	public void setSecondaryProducingChoice(Resource[] secondaryProducingChoice)
	{
		if (this.secondaryProducingChoice != null)
		{
			this.resourcesProducedGains.remove(this.secondaryProducingChoice[0]);
			this.resourceProducedCosts.remove(this.secondaryProducingChoice[1]);
		}
		this.secondaryProducingChoice = secondaryProducingChoice;
		addResourceProduceGain(secondaryProducingChoice[0]);
		addResourceProduceCost(secondaryProducingChoice[1]);
	}

	/**
	 * @return returns how many goods have been produced.
	 */
	// public abstract int produceGoods();

}
